package com.tedu.parkinglot.carLog.controller;

import com.tedu.parkinglot.base.response.JsonResult;
import com.tedu.parkinglot.carLog.pojo.dto.CarLogQuery;
import com.tedu.parkinglot.carLog.pojo.dto.CarLogSaveParam;
import com.tedu.parkinglot.carLog.pojo.vo.CarLogVO;
import com.tedu.parkinglot.carLog.pojo.vo.ChargeVO;
import com.tedu.parkinglot.carLog.service.CarLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/carLog")
public class CarLogController {

    @Autowired
    private CarLogService carLogService;


    @GetMapping("select")
    public JsonResult select(CarLogQuery carLogQuery) {
        List<CarLogVO> list = carLogService.select(carLogQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult save(CarLogSaveParam param) {
        log.info("车辆入场：{}", param);
        carLogService.save(param);
        return JsonResult.ok();

    }

    @PostMapping("exit/{id}")
    public JsonResult exit(@PathVariable Long id) {
        log.info("车辆出场：{}", id);
        ChargeVO chargeVO = carLogService.exit(id);
        return JsonResult.ok(chargeVO);
    }

}
